package com.gengzp.common.enums;

import lombok.Getter;

/**
 * @ClassName PermissionEnum
 * @Description 权限枚举类
 * @Author gengzp
 * @Date 2025/9/15 15:24
 */
@Getter
public enum PermissionEnum {

    ROOT("root", "根节点", null, "系统所有权限的根节点"),

    // =================================== 用户管理 ===================================
    USER_MANAGE("user", "用户管理", ROOT, "拥有对用户的全部读写操作的权限"),
    USER_WRITE("user:write", "用户写", USER_MANAGE, "拥有对用户的写权限"),
    USER_CREATE("user:write:create", "用户添加", USER_WRITE, "拥有对用户的添加权限"),
    USER_EDIT("user:write:edit", "用户编辑", USER_WRITE, "拥有对用户的编辑权限"),
    USER_REMOVE("user:write:remove", "用户删除", USER_WRITE, "拥有对用户的删除权限"),
    USER_READ("user:read", "用户读", USER_MANAGE, "拥有对用户的读权限, 包括: 查询列表, 查询详情"),

    // =================================== 角色管理 ===================================
    ROLE_MANAGE("role", "角色管理", ROOT, "拥有对角色的全部读写操作的权限"),
    ROLE_WRITE("role:write", "角色写", ROLE_MANAGE, "拥有对角色的写权限"),
    ROLE_CREATE("role:write:create", "角色添加", ROLE_WRITE, "拥有对角色的添加权限"),
    ROLE_EDIT("role:write:edit", "角色编辑", ROLE_WRITE, "拥有对角色的编辑权限"),
    ROLE_REMOVE("role:write:remove", "角色删除", ROLE_WRITE, "拥有对角色的删除权限"),
    ROLE_READ("role:read", "角色读", ROLE_MANAGE, "拥有对角色的读权限, 包括: 查询列表, 查询详情"),

    // =================================== 权限管理 ===================================
    PERMISSION_MANAGE("permission", "权限管理", ROOT, "拥有对权限的全部读写操作的权限"),
    PERMISSION_ALLOCATE("permission:allocate", "权限分配", PERMISSION_MANAGE, "拥有对权限的分配权限, 可以指定为角色添加或移除权限"),
    PERMISSION_READ("permission:read", "权限读", PERMISSION_MANAGE, "拥有对权限的读权限, 包括: 查询列表, 详情"),

    // =================================== 日志管理 ===================================
    LOG_MANAGE("log", "日志管理", ROOT, "拥有对日志的全部读写操作的权限"),
    LOG_READ("log:read", "日志读", LOG_MANAGE, "拥有对日志的读权限, 可以查询日志"),

    // =================================== 消息队列管理 ===================================
    MQ_MANAGE("mq", "消息队列管理", ROOT, "拥有对消息队列的全部读写操作的权限"),
    MQ_WRITE("mq:resend", "消息重发", MQ_MANAGE, "拥有消息重发权限"),
    MQ_READ("mq:read", "消息队列读", MQ_MANAGE, "拥有对消息队列的读权限, 可以查询消息队列"),
    MQ_TOPIC_WRITE("mq:topic:write", "消息队列主题写", MQ_MANAGE, "拥有对消息队列主题的写权限"),

    // =================================== 定时任务管理 ===================================
    TASK_MANAGE("task", "定时任务管理", ROOT, "拥有对定时任务的全部读写操作的权限"),
    TASK_WRITE("task:write", "定时任务写", TASK_MANAGE, "拥有对定时任务的写权限"),
    TASK_CREATE("task:write:create", "定时任务添加", TASK_WRITE, "拥有对定时任务的添加权限"),
    TASK_EDIT("task:write:edit", "定时任务编辑", TASK_WRITE, "拥有对定时任务的编辑权限"),
    TASK_REMOVE("task:write:remove", "定时任务删除", TASK_WRITE, "拥有对定时任务的删除权限"),
    TASK_READ("task:read", "定时任务读", TASK_MANAGE, "拥有对定时任务的读权限, 可以查询定时任务"),
    TASK_EXECUTE("task:execute", "定时任务手动执行", TASK_MANAGE, "拥有对定时任务的执行权限, 可以手动执行定时任务"),

    // =================================== 版本迭代管理 ===================================
    VERSION_ITERATION_MANAGE("version_iteration", "版本迭代管理", ROOT, "拥有对版本迭代的全部读写操作的权限"),
    VERSION_ITERATION_WRITE("version_iteration:write", "版本迭代写", VERSION_ITERATION_MANAGE, "拥有对版本迭代的写权限"),
    VERSION_ITERATION_CREATE("version_iteration:write:create", "版本迭代添加", VERSION_ITERATION_WRITE, "拥有对版本迭代的添加权限"),
    VERSION_ITERATION_EDIT("version_iteration:write:edit", "版本迭代编辑", VERSION_ITERATION_WRITE, "拥有对版本迭代的编辑权限"),
    VERSION_ITERATION_REMOVE("version_iteration:write:remove", "版本迭代删除", VERSION_ITERATION_WRITE, "拥有对版本迭代的删除权限"),
    VERSION_ITERATION_CHANGE_STATUS("version_iteration:write:change_status", "版本迭代变更流程", VERSION_ITERATION_MANAGE, "拥有对版本迭代的变更流程权限, 可以变更版本迭代流程"),
    VERSION_ITERATION_READ("version_iteration:read", "版本迭代读", VERSION_ITERATION_MANAGE, "拥有对版本迭代的读权限, 可以查询版本迭代"),

    // =================================== 服务治理管理 ===================================
    SERVICE_GOVERNANCE_MANAGE("service_governance", "服务治理管理", ROOT, "拥有对服务治理的全部读写操作的权限"),
    SERVICE_GOVERNANCE_WRITE("service_governance:write", "服务治理写", SERVICE_GOVERNANCE_MANAGE, "拥有对服务治理的写权限"),
    SERVICE_GOVERNANCE_CREATE("service_governance:write:create", "服务治理添加", SERVICE_GOVERNANCE_WRITE, "拥有对服务治理的添加权限"),
    SERVICE_GOVERNANCE_EDIT("service_governance:write:edit", "服务治理编辑", SERVICE_GOVERNANCE_WRITE, "拥有对服务治理的编辑权限"),
    SERVICE_GOVERNANCE_REMOVE("service_governance:write:remove", "服务治理删除", SERVICE_GOVERNANCE_WRITE, "拥有对服务治理的删除权限"),
    SERVICE_GOVERNANCE_READ("service_governance:read", "服务治理读", SERVICE_GOVERNANCE_MANAGE, "拥有对服务治理的读权限, 可以查询服务治理"),

    ;

    // 权限编码
    private final String code;

    // 权限名称
    private final String name;

    // 父级权限编码
    private final PermissionEnum parentPermission;

    // 权限描述
    private final String description;

    PermissionEnum(String code, String name, PermissionEnum parentPermission, String description) {
        this.code = code;
        this.name = name;
        this.parentPermission = parentPermission;
        this.description = description;
    }

    /**
     * 根据编码获取权限名称
     *
     * @param code 权限编码
     * @return 权限名称
     */
    public static PermissionEnum getByCode(String code) {
        for (PermissionEnum v : PermissionEnum.values()) {
            if (v.getCode().equals(code)) {
                return v;
            }
        }
        return null;
    }

}
